import java.util.ArrayList;
import java.util.List;

/**
 * @author ZCR
 * @create 2025/9/8 21:21
 */
public class Solution442 {
    public List<Integer> findDuplicates(int[] nums) {
        List<Integer> res = new ArrayList<Integer>();
        for(int i = 0; i < nums.length; i++){
            int index = Math.abs(nums[i]) -1;
            if(nums[index] < 0){
                res.add(Math.abs(nums[i]));
            }else{
                nums[index]*=-1;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Solution442 s = new Solution442();
        System.out.println(s.findDuplicates(new int[]{4,3,2,7,8,2,3,1}));
    }
}
